package main

import (
	"fmt"
	"time"
)

func main() {

	//1.获取当前时间
	now := time.Now()
	fmt.Printf("time= %v, \n time type= %T", now, now)
	//time= 2021-06-26 11:54:38.2272511 +0800 CST m=+0.009000201,
	//time type= time.Time

	//2.获取时分秒
	fmt.Println("年=", now.Year())
	fmt.Println("月=", int(now.Month()))
	fmt.Println("日=", now.Day())
	fmt.Println("时=", now.Hour())
	fmt.Println("分=", now.Minute())
	fmt.Println("秒=", now.Second())

	//3.格式化日期时间：
	//方式一
	dateStr := fmt.Sprintf("当前年月日：%d-%d-%d %d:%d:%d", now.Year(), now.Month(),
		now.Day(), now.Hour(), now.Second(), now.Minute())
	fmt.Println(dateStr)

	//方式二 语言规定时间的点，据说是突然想创建一门新语言的想法的时间点
	fmt.Printf(now.Format("2006/01/02 15:04:05"))
	fmt.Println()
	fmt.Printf(now.Format("2006/01/02"))
	fmt.Println()
	fmt.Printf(now.Format("15:04:05 \n"))

	//4.时间常量
	// const(
	// 	Nanosecond Duration = 1 一纳秒
	// 	Microsecond = 1000 * Nanosecond 微秒
	// 	Millisecond = 1000 * Microsecond 毫秒
	// 	Second = 1000 *  Millisecond 秒
	// 	Minute = 60 * Second 分钟
	// 	Hour = 60 * Minute 小时
	// )

	//5.常量的应用。结合sleep
	time.Sleep(time.Second * 2)
	time.Sleep(time.Millisecond * 100)

	//6.获取随机的数字 unix, unixNano
	fmt.Println(now.Unix())
	fmt.Println(now.UnixNano())

}
